<?php

class Disciplina{
    public $sigla;
    public $credito;
    public $titulo;
    
    public function __construct($xmlDisciplina){

        $attributes = $xmlDisciplina->attributes();
        
        $this->sigla = (string)$attributes['sigla'];
        
        if(isset($attributes['cred'])){
            $this->credito = (string)$attributes['cred'];
        }
        
        if(isset($attributes['titulo'])){
            $this->titulo = (string)$attributes['titulo'];
        }
    }
    
    public function toJson(){
        $json = array(
            'abbreviation' => $this->sigla,
            'credits' => $this->credito
        );
        
        return json_encode($json);
    }
}